package com.ruoyi.user.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.user.domain.XxUser;
import com.ruoyi.user.service.IXxUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户Controller
 * 
 * @author ruoyi
 * @date 2022-06-17
 */
@Controller
@RequestMapping("/user/manage")
public class XxUserController extends BaseController
{
    private String prefix = "user/manage";

    @Autowired
    private IXxUserService xxUserService;

    @RequiresPermissions("user:manage:view")
    @GetMapping()
    public String manage()
    {
        return prefix + "/manage";
    }

    /**
     * 查询用户列表
     */
    @RequiresPermissions("user:manage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(XxUser xxUser)
    {
        startPage();
        List<XxUser> list = xxUserService.selectXxUserList(xxUser);
        return getDataTable(list);
    }

    /**
     * 导出用户列表
     */
    @RequiresPermissions("user:manage:export")
    @Log(title = "用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(XxUser xxUser)
    {
        List<XxUser> list = xxUserService.selectXxUserList(xxUser);
        ExcelUtil<XxUser> util = new ExcelUtil<XxUser>(XxUser.class);
        return util.exportExcel(list, "用户数据");
    }

    /**
     * 新增用户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户
     */
    @RequiresPermissions("user:manage:add")
    @Log(title = "用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(XxUser xxUser)
    {
        return toAjax(xxUserService.insertXxUser(xxUser));
    }

    /**
     * 修改用户
     */
    @RequiresPermissions("user:manage:edit")
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        XxUser xxUser = xxUserService.selectXxUserByUserId(userId);
        mmap.put("xxUser", xxUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户
     */
    @RequiresPermissions("user:manage:edit")
    @Log(title = "用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(XxUser xxUser)
    {
        return toAjax(xxUserService.updateXxUser(xxUser));
    }

    /**
     * 删除用户
     */
    @RequiresPermissions("user:manage:remove")
    @Log(title = "用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(xxUserService.deleteXxUserByUserIds(ids));
    }
}
